package com.example.demo.service.impl;

import com.example.demo.service.AsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
@EnableAsync
public class AsyncServiceImpl implements AsyncService {

    // 这里执行实际的业务逻辑，在这里我们就是用一个简单的遍历来模拟

    @Async
    public void serviceTest(){
        //这个t也可以是x  "->"后面是函数体
        Arrays.stream(new int[]{1,2,3,4,5,6,7,8,9,10}).forEach(t->{
            try {
                Thread.sleep(1000);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
            System.out.println("获取number为"+t);

        });
    }
}
